package com.cq.hd.product.controller;

import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.product.api.TbGoodsApi;
import com.cq.hd.product.api.dto.*;
import com.cq.hd.product.api.vo.GoodsActivePageVo;
import com.cq.hd.product.api.vo.GoodsCountVo;
import com.cq.hd.product.api.vo.GoodsPageVo;
import com.cq.hd.product.service.TbGoodsService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-23
 */
@RestController
public class TbGoodsController implements TbGoodsApi {

    @Autowired
    private TbGoodsService goodsService;

    @ApiOperation(value = "商品列表")
    @ApiResponse(response = GoodsPageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<GoodsPageVo>> pageGoods(GoodsPageDto goodsPageDto) {
        return ResultGenerator.success(goodsService.pageGoods(goodsPageDto));
    }

    @ApiOperation(value = "发布商品")
    @ApiImplicitParam(name = "goodsReleaseDto", value = "实体", paramType = "body", dataType = "GoodsReleaseDto")
    @Override
    public Result<Object> releaseGoods(@RequestBody GoodsReleaseDto goodsReleaseDto) {
        return ResultGenerator.success(goodsService.releaseGoods(goodsReleaseDto));
    }

    @ApiOperation(value = "批量下架商品")
    @ApiImplicitParam(name = "goodsOffDto", value = "实体", paramType = "body", dataType = "GoodsOffDto")
    @Override
    public Result<Object> offGoods(@RequestBody GoodsOffDto goodsOffDto) {
        return ResultGenerator.success(goodsService.offGoods(goodsOffDto));
    }

    @ApiOperation(value = "批量上架")
    @ApiImplicitParam(name = "goodsOnDto", value = "实体", paramType = "body", dataType = "GoodsOnDto")
    @Override
    public Result<Object> batchOnGoods(@RequestBody GoodsOnDto goodsOnDto) {
        return ResultGenerator.success(goodsService.batchOnGoods(goodsOnDto));
    }

    @ApiOperation(value = "上架商品")
    @ApiImplicitParam(name = "goodsOnDto", value = "实体", paramType = "body", dataType = "GoodsOnDto")
    @Override
    public Result<Object> onGoods(@RequestBody GoodsOnDto goodsOnDto) {
        return ResultGenerator.success(goodsService.onGoods(goodsOnDto));
    }

    @ApiOperation(value = "改库存")
    @ApiImplicitParam(name = "goodsStockUpdateDto", value = "实体", paramType = "body", dataType = "GoodsStockUpdateDto")
    @Override
    public Result<Object> updateGoodsStock(@RequestBody GoodsStockUpdateDto goodsStockUpdateDto) {
        return ResultGenerator.success(goodsService.updateGoodsStock(goodsStockUpdateDto));
    }

    @ApiOperation(value = "改价")
    @ApiImplicitParam(name = "goodsPriceUpdateDto", value = "实体", paramType = "body", dataType = "GoodsPriceUpdateDto")
    @Override
    public Result<Object> updateGoodsPrice(@RequestBody GoodsPriceUpdateDto goodsPriceUpdateDto) {
        return ResultGenerator.success(goodsService.updateGoodsPrice(goodsPriceUpdateDto));
    }

    @ApiOperation(value = "编辑商品")
    @ApiImplicitParam(name = "goodsUpdateDto", value = "实体", paramType = "body", dataType = "GoodsUpdateDto")
    @Override
    public Result<Object> updateGoods(@RequestBody GoodsUpdateDto goodsUpdateDto) {
        return ResultGenerator.success(goodsService.updateGoods(goodsUpdateDto));
    }

    @ApiOperation(value = "删除商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品id", required = true, paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "merchantId", value = "商户id", required = true, paramType = "query", dataType = "Long")
    })
    @Override
    public Result<Object> deleteGoods(Long id, Long merchantId) {
        return ResultGenerator.success(goodsService.deleteGoods(id, merchantId));
    }

    @Override
    public Result<Object> deleteBusinessMerchantGoods(Long id, Long businessMerchantId) {
        return ResultGenerator.success(goodsService.deleteBusinessMerchantGoods(id, businessMerchantId));
    }

    @ApiOperation(value = "批量删除")
    @ApiImplicitParam(name = "goodsDelDto", value = "实体", paramType = "body", dataType = "GoodsDelDto")
    @Override
    public Result<Object> batchDeleteGoods(@RequestBody GoodsDelDto goodsDelDto) {
        return ResultGenerator.success(goodsService.batchDeleteGoods(goodsDelDto));
    }

    @ApiOperation(value = "创建活动选择商品列表")
    @ApiResponse(response = GoodsActivePageVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Page<GoodsActivePageVo>> pageGoodsActive(GoodsActivePageDto goodsActivePageDto) {
        return ResultGenerator.success(goodsService.pageGoodsActive(goodsActivePageDto));
    }

    @ApiOperation(value = "查询商户的在售商品数")
    @ApiResponse(response = Integer.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<Integer> onGoodsCount(Long merchantId) {
        return ResultGenerator.success(goodsService.onGoodsCount(merchantId));
    }

    @ApiOperation(value = "获取商户的商品每个状态的个数")
    @ApiResponse(response = GoodsCountVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<GoodsCountVo>> getGoodsCount(Long merchantId) {
        return ResultGenerator.success(goodsService.getGoodsCount(merchantId));
    }

    @ApiOperation(value = "根据商户id获取该商户（策划人）为底下商户添加的商品每个状态的个数")
    @ApiResponse(response = GoodsCountVo.class, code = 200, message = "接口返回对象参数")
    @Override
    public Result<List<GoodsCountVo>> getBusinessMerchantGoodsCount(Long merchantId) {
        return ResultGenerator.success(goodsService.getBusinessMerchantGoodsCount(merchantId));
    }

    @ApiOperation(value = "扫描已上架的商品的库存,如果低于5，发送系统通知给商户")
    @Override
    public Result<Boolean> scanOnGoodsStock() {
        return ResultGenerator.success(goodsService.scanOnGoodsStock());
    }

}
